package com.waitingsnow.modules.shell.view.giftItem
{
import assets.shellView.GiftBgAsset;

import com.waitingsnow.core.display.control.ToolTipManager;
import com.waitingsnow.core.util.display.DisplayUtil;
import com.waitingsnow.core.model.vo.GiftVO;

import flash.display.Loader;
import flash.display.Shape;
import flash.display.Sprite;
import flash.events.Event;
import flash.events.MouseEvent;
import flash.filters.GlowFilter;
import flash.net.URLRequest;

/**
 * 
 * @author waitingsnow
 * $Id: BaseGiftItem.as 2 2012-05-17 10:10:03Z cgslendy@gmail.com $
 */
public class BaseGiftItem extends Sprite
{
	//==========================================================================
	//  Constructor
	//==========================================================================
	/**
	 * Constructs a new <code>BaseGiftItem</code> instance.
	 * 
	 */
	public function BaseGiftItem()
	{
		initDisplay();
	}
	
	//==========================================================================
	//  Variables
	//==========================================================================
	private var imgLoader:Loader;
	private var giftBgAsset:GiftBgAsset;
	private var _itemWidth:int = 30;
	private var _itemHeight:int = 30;
	
	//==========================================================================
	//  Properties
	//==========================================================================
	private var _giftVO:GiftVO;
	public function get giftVO():GiftVO
	{
		return _giftVO;
	}
	
	//==========================================================================
	//  Methods
	//==========================================================================
	private function initDisplay():void
	{
		updateSize();
		giftBgAsset = new GiftBgAsset();
		addChild(giftBgAsset);
		buttonMode = true;
		/*addEventListener(MouseEvent.ROLL_OVER, rollOverHandler);
		addEventListener(MouseEvent.ROLL_OUT, rollOutHandler);*/
	}
	
	private function updateSize():void
	{
		/*DisplayUtil.setGraphics(this, _itemWidth, _itemHeight);*/
	}
	
	public function setData(vo:GiftVO):void
	{
		_giftVO = vo;
		if (!imgLoader)
		{
			imgLoader = new Loader();
			imgLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, imgLoaderCompleteHandler);
		}
		vo.iconPath && imgLoader.load(new URLRequest(vo.iconPath));
		var tipStr:String = vo.giftName + "(" + vo.giftPrice + "喜币)";
		vo.giftInfo && (tipStr += "\n" + vo.giftInfo);
		ToolTipManager.getInstance().addToolTip(this, tipStr);
	}
	
	public function setSize(width:int, height:int):void
	{
		_itemWidth = width;
		_itemHeight = height;
		updateSize();
	}
	
	//==========================================================================
	//  Event Handlers
	//==========================================================================
	private function imgLoaderCompleteHandler(event:Event):void
	{
		/*imgLoader.width = _itemWidth;
		imgLoader.height = _itemHeight;*/
		imgLoader.mouseChildren = imgLoader.mouseEnabled = false;
		addChild(imgLoader);
	}
	
	/*private function rollOverHandler(event:MouseEvent):void
	{
		filters = [new GlowFilter()]
	}
	
	private function rollOutHandler(event:MouseEvent):void
	{
		filters = [];
	}*/
}
}